home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: Settle a bet please
- Date: 30 Mar 1996 10:40:56 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4jjo6o$cqj@solutions.solon.com>
- References: <4jfopb$o9n@news1.sympatico.ca> <KASPER.96Mar29073654@acm.org> <mjs.828111568@hubcap> <KASPER.96Mar30085147@acm.org>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <KASPER.96Mar30085147@acm.org>, <kasperowski@acm.org> wrote:
- >In private e-mail, someone said the same thing to me, and I replied,
- >"sure, I guess you're right." I was wrong -- this is illegal.
-
- Nope. It's a special case exception, which is mentioned explicitly in
- the standard. K&R should mention it.
-
- >In ANSI C,
-
- > char name[7] = "My name";
-
- >which is the same as
-
- > char name[7] = {'M', 'y', ' ', 'n', 'a', 'm', 'e', '\0'};
-
- But it isn't. It's a special case. 6.5.7:
- An array of character type may be initialized by a character
- string literal, optionally enclosed in barces. Successive
- characters of the character string literal (including the
- terminating null character IF THERE IS ROOM OR IF THE ARRAY
- IS OF UNKNOWN SIZE) initialize the elements of the array.
-
-
- >is *not* legal. Section A8.7 on p. 219 of Appendix A of my copy of
- >K&R's _The C Programming Language_, 2nd ed., says:
-
- > If the array has fixed size, the number of initializers may not
- > exceed the number of members of the array . . .
-
- And then goes on to say, in the next paragraph, that initializing with
- a string literal is a special case, and says
- "if its size is fixed, the number of characters in the string, NOT
- COUNTING THE TERMINATING NULL CHARACTER, must not exceed the size of
- the array."
-
- This is a feature, so things like
- char octdig[8] = "01234567";
- work.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-